﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Http;
using System.Web.Http.WebHost;
using System.Web.Routing;
using System.Web.SessionState;
using Newtonsoft.Json;
using ZQNB.Common.Web;

namespace ZQNB.Web
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            //// Web API 配置和服务

            ////循环问题
            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            //JsonSerializerSettings serializerSetting = new JsonSerializerSettings
            //{
            //    ContractResolver = new DynamicContractResolver(),
            //    ReferenceLoopHandling = ReferenceLoopHandling.Serialize
            //};

            //config.Formatters.JsonFormatter.SerializerSettings = serializerSetting;

            //如果有自定义的路由策略，在此注册
            config.MapHttpAttributeRoutes();

            //让API支持Session
            ApiSessionSupport.Setup();

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "webapi/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);

            config.Routes.MapHttpRoute(
                name: "RpcApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );


            //config.EnableSystemDiagnosticsTracing();
            config.EnsureInitialized();

            //config.Filters.Add(new HostAuthenticationFilter("Bearer")); 
        }
    }
}
